package cn.itcast;

import org.quartz.*;

import java.util.Date;

/**
 * @program: schedule
 * @description: quartz定时任务的job服务
 * @author: zhanghz001
 * @create: 2021-08-03 20:32
 **/
//表示job的参数修改,下一次执行job时候生效
@PersistJobDataAfterExecution
//不同时执行任务,任务间需要串行,出现MissFire的时候,任务执行完成后,立即执行堆积的队列
@DisallowConcurrentExecution
public class ZhzJob implements Job {
    private String name;
    
    public void setName(String name) {
        this.name = name;
    }
    
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        System.out.println(Thread.currentThread().getName() + "任务开始执行" + new Date());
        
        System.out.println(Thread.currentThread().getName() + "任务执行结束" + new Date());
    }
    
    /**
     * 这个是如何传递参数,让参数生效
     *
     * @param jobExecutionContext
     * @throws JobExecutionException
     */
    public void execute1(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        //获取参数的方式 1
        String name1 = jobExecutionContext.getJobDetail().getJobDataMap().getString("name");
        System.out.println("通过参数获取的..." + name1);
        System.out.println("本地获取的..." + name);
        jobExecutionContext.getJobDetail().getJobDataMap().put("name", "itheima");
        System.out.println("本地获取的..." + name);
        System.out.println("执行当前任务..." + new Date());
        
    }
}
